var gulp = require('gulp');
var gulpif = require('gulp-if');
var rev = require('gulp-rev');
var revCollector = require('gulp-rev-collector');
var less = require('gulp-less');
var minifyCSS = require('gulp-clean-css');
var livereload = require('gulp-livereload');
var config = require('../config').less;
var configDes = require('../config').des;

var postcss = require('gulp-postcss');
var px2rem = require('postcss-px2rem');

gulp.task('less', function () {
    //此处函数为自动转换px->rem
    var processors = [px2rem({
        remUnit: 75
    })];
    return gulp.src(config.src)
        .pipe(less())
        .pipe(minifyCSS())
        //.pipe(postcss(processors))
        .pipe(gulp.dest(config.dest))
        .pipe(livereload())
});

gulp.task('revLess', function () {
    return gulp.src(config.revSrc)
        .pipe(less())
        .pipe(minifyCSS())
        .pipe(rev())
        .pipe(gulp.dest(config.dest))
        .pipe(rev.manifest())
        .pipe(gulp.dest(config.rev))
        .pipe(livereload())
});

gulp.task('revCss', function () {
    return gulp.src([configDes.all, config.all])
        .pipe(revCollector())
        .pipe(gulp.dest(config.revCss))
});